package com.wzk.controller;

import com.wzk.annotation.LogFlag;
import com.wzk.pojo.PageResult;
import com.wzk.pojo.Result;
import com.wzk.pojo.Student;
import com.wzk.pojo.StudentQueryParam;
import com.wzk.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result pageQuery(StudentQueryParam studentQueryParam){
        log.info("分页查询返回学生信息");
        PageResult<Student> result = studentService.pageQuery(studentQueryParam);
        return Result.success(result);
    }
    @LogFlag
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("删除id为{}的数据",ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }
    @LogFlag
    @PostMapping
    public Result addStudent(@RequestBody Student student){
        log.info("添加学生信息{}",student);
        studentService.addStudent(student);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询id为{}的学生信息",id);
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }
    @LogFlag
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        log.info("修改学生信息{}",student);
        studentService.updateStudent(student);
        return Result.success();
    }
    @LogFlag
    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable Integer id,@PathVariable Integer score){
        log.info("修改学生id为{}的违规次数和违规分数",id);
        studentService.updateViolation(id,score);
        return Result.success();
    }
}
